package com.vincent.common.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by vincent on 11/6/14.
 */
public class DataUtil {
    /**
     * 判断字符是否在数组中
     * @param key
     * @param array
     * @return
     */
    public static boolean isExistArray(String key,String []array){
        for(String s:array){
            if(s.equals(key)){
                return true;
            }
        }
        return false;
    }

    /**
     * 获取昵称
     * @param nickName
     * @param realName
     * @param userName
     * @return
     */
    public static String getNickName(String nickName,String realName,String userName){
        if(StringUtils.isNotBlank(nickName)){
            return nickName;
        }
        if(StringUtils.isNotBlank(realName)){
            return realName;
        }
        return userName;
    }

    /**
     * 组织查询字段
     * @param columns
     * @return
     */
    public static String getQueryColumns(String ...columns){
        if(columns==null||columns.length<=0){
            return "";
        }
        StringBuilder sb=new StringBuilder();
        for(String s:columns){
            sb.append(","+s);
        }
        String substring = sb.substring(1);
        return substring;
    }

    public static String getQueryContions(String []columns){
        if(columns==null||columns.length<=0){
            return "";
        }
        StringBuilder sb=new StringBuilder();
        for(String s:columns){
            sb.append(" AND "+s+"=? ");
        }
        return sb.toString();
    }


}
